<?php

namespace App\V1\Controllers;

use \App\Helpers\CommonUtils,
	\App\Helpers\RsaHelper;
use App\Http\Request;

/**
 * 接口控制器基类
 * @package App\V1\Controllers
 *
 * @property \App\Http\Request $request
 * @property \App\Http\Response $response
 */
class ControllerBase extends \Phalcon\Mvc\Controller {

	#region 属性

	/**
	 * 响应数据配置数组
	 * @var array
	 */
	protected $lang;

	/**
	 * 资源库对象
	 * @var \App\V1\Repositories
	 */
	protected $repository;

	#endregion

	#region 初始化

	/**
	 * 初始化，在事件“beforeExecuteRoute”成功执行后才会被调用
	 */
	public function initialize() {
		$this->request =  $this->di->getShared("request");
		$this->response =  $this->di->getShared("response");
	}

	#endregion


	#region RSA签名、验签

	/**
	 * 添加RSA签名
	 * @param $data 需要签名的字符串
	 * @return string RSA签名字符串
	 */
	protected function rsaSign($data) {
		$priKey = $this->di->getShared("config")->rsa->request->priKey;
		return RsaHelper::RsaSign($data, $priKey);
	}

	#endregion
}